﻿using UnityEngine;
using System.Collections;

namespace TCG 
{
	public class TCGGame
	{
		public TCGGame ()
		{
			initialized = false;
			m_luaInterface = new LuaInterface ();
		}

		public void Start ()
		{
			CoroutineDelegate.instance.StartCoroutine (Co_Initialize ());
		}

		IEnumerator Co_Initialize ()
		{
			// 初始化lua
			m_luaInterface.Initialize ("main.lua");
			yield return null;
			
			// 初始化调试窗口
			DebugWindow.instance.Initialize (m_luaInterface.luaState);
			yield return null;
			
			// 初始化资源数据库
			GameAssetsDatabase.instance.Initialize (delegate () {
				initialized = true;
				Debug.Log ("let's go");

				m_luaInterface.Start ();
			});
		}

		public void Update ()
		{
			if (initialized)
			{
				m_luaInterface.Update ();
			}
		}

		bool initialized { get; set; }

		LuaInterface m_luaInterface = null;
	}
}